home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / modex32w.zip / SHPAGE2.ASM < prev    next >
Assembly Source File  |  1995-02-21  |  3KB  |  97 lines

  1.         .386p
  2.         locals
  3.         include w.inc
  4.  
  5. ; Shows the page at the specified offset in the bitmap. Page is displayed when 
  6. ; this routine returns. This code first appeared in PC Techniques.
  7. ;
  8. ; C near-callable as: void ShowPage(unsigned x, y);
  9. ;
  10. ; Modified Aug 30, 1994 (ykumanan)
  11. ; ) Made code 32 bit pm (not fully optimized)
  12. ; ) Added pel panning code for smooth horizontal scrolling
  13. ; ) Converted to coordinate scrolling for easier mapping
  14. ;
  15.  
  16. INPUT_STATUS_1  equ     03dah   ;Input Status 1 register
  17. CRTC_INDEX      equ     03d4h   ;CRT Controller Index reg
  18. START_ADDRESS_HIGH equ  0ch     ;bitmap start address high byte
  19. START_ADDRESS_LOW equ   0dh     ;bitmap start address low byte
  20. AC_INDEX        equ  03c0h   ;Attribute controller index register
  21. PEL_PANNING     equ    13h   ; Pel panning register index in AC
  22.  
  23. ShowPageParms   struc
  24.         dd      2 dup (?) ;pushed EBP and return address
  25. X       dd      ?
  26. Y       dd      ?       ; location in bitmap to display
  27. ShowPageParms   ends
  28.  
  29.         @dseg
  30.  
  31.         extrn   SCREEN_WIDTH:dword
  32.  
  33.         ends
  34.         @cseg
  35.  
  36.         public  _ShowPage
  37. _ShowPage       proc    near
  38.         push    ebp      ;preserve caller's stack frame
  39.         mov     ebp,esp   ;point to local stack frame
  40.         push    esi
  41.         push    ebx
  42.  
  43. ; Wait for display enable to be active (status is active low), to be
  44. ; sure both halves of the start address will take in the same frame.
  45.         mov     esi, [ebp+X]
  46.         mov     eax, [SCREEN_WIDTH]
  47.         mov     ecx, [ebp+Y]
  48.         mul     ecx                     ; row offset
  49.         mov     ecx, esi
  50.         shr     ecx, 2
  51.         add     eax, ecx                ; make full offset
  52.  
  53.         and     esi, 03h                ; select pel pan register value
  54.         shl     esi, 9                  ; * 2 to make pel pan index
  55.                                         ; and move to high byte
  56.         or      esi, PEL_PANNING+20h    ; put pel info in low byte
  57.  
  58.         mov     bl,START_ADDRESS_LOW        ;preload for fastest
  59.         mov     bh, al                      ; flipping once display
  60.         mov     cl,START_ADDRESS_HIGH       ; enable is detected
  61.         mov     ch, ah
  62.         mov     dx,INPUT_STATUS_1
  63. WaitDE:
  64.         in      al,dx
  65.         test    al,01h
  66.         jnz     WaitDE  ;display enable is active low (0 = active)
  67. ; Set the start offset in display memory of the page to display.
  68.         mov     dx,CRTC_INDEX
  69.         mov     ax,bx
  70.         out     dx,ax   ;start address low
  71.         mov     ax,cx
  72.         out     dx,ax   ;start address high
  73. ; Now wait for vertical sync, so the other page will be invisible when
  74. ; we start drawing to it.
  75.         mov     dx,INPUT_STATUS_1
  76. WaitVS:
  77.         in      al,dx
  78.         test    al,08h
  79.         jz      WaitVS  ;vertical sync is active high (1 = active)
  80.  
  81.         mov     dx, AC_INDEX
  82.         mov     ax,si             ; Point the attribute controller to pel pan
  83.     cli
  84.         out     dx,al             ; reg. Bit 5 also set to prevent blanking
  85.         mov     al,ah
  86.         out     dx,al             ; load new Pel Pan setting.
  87.     sti
  88.  
  89.         pop     ebx
  90.         pop     esi
  91.         pop     ebp      ;restore caller's stack frame
  92.         ret
  93. _ShowPage       endp
  94.         ends
  95.         end
  96.  
  97.